//Name: Sara Thorup
#include "dominion.h"
#include "dominion_helpers.h"
#include <string.h>
#include <stdio.h>
#include <assert.h>
#include "rngs.h"

void testNoCards();
void testNoCardsMatch();
void testOneCardMatch();
void testManyMatchingCards();
/*
Unit tests for  int fullDeckCount(int player, int card, struct gameState *state)
fullDeckCount() returns the number of a specific card is in a specific players hand

Things to test:
- When the player has no cards at all
- When the player has no matching cards
- When the player has one matching card
- When the player has many matching cards
- Test for deck, hand, and discard
*/


int main(int argc, char *argv[]) {
	printf("\n ===== Testing fullDeckCount() =====\n");
    testNoCards();
    testNoCardsMatch();
    testOneCardMatch();
    testManyMatchingCards();
    return 0;
}

void testManyMatchingCards() {
	//setup
	struct gameState* gameState = newGame();
	int testPlayer = 0;
	int testCard = estate;
	int numPlayers = 2;
	int kingdomCards[10] = {adventurer, council_room, feast, gardens, mine, remodel, smithy, village, baron, great_hall};
	int randomSeed = 10;

	if (initializeGame(numPlayers, kingdomCards, randomSeed, gameState) != 0){
		printf("Error initalizing game. \n");
		return;
	}

	//Fill hand, deck, and discard with 3 test cards
	//Make sure that the counts are updated
	gameState->handCount[testPlayer] = 3;
    gameState->discardCount[testPlayer] = 3;
    gameState->deckCount[testPlayer] = 3;
    gameState->hand[testPlayer][0] = gold;
    gameState->hand[testPlayer][1] = gold;
	gameState->hand[testPlayer][2] = testCard;
	gameState->deck[testPlayer][0] = gold;
    gameState->deck[testPlayer][1] = testCard;
	gameState->deck[testPlayer][2] = gold;
	gameState->discard[testPlayer][0] = gold;
    gameState->discard[testPlayer][1] = testCard;
	gameState->discard[testPlayer][2] = gold;

	int expectedCardCount = 3;
	if (expectedCardCount == fullDeckCount(testPlayer, testCard, gameState)) {
		printf("fullDeckCount(): PASS when player has many matching cards \n");
	}
	else {
		printf("fullDeckCount(): FAIL when player has many matching card \n");
	}
}
void testOneCardMatch() {
	//setup
	struct gameState* gameState = newGame();
	int testPlayer = 0;
	int testCard = estate;
	int numPlayers = 2;
	int kingdomCards[10] = {adventurer, council_room, feast, gardens, mine, remodel, smithy, village, baron, great_hall};
	int randomSeed = 10;

	if (initializeGame(numPlayers, kingdomCards, randomSeed, gameState) != 0){
		printf("Error initalizing game. \n");
		return;
	}

	//Fill hand, deck, and discard with one test card
	//Make sure that the counts are updated
	gameState->handCount[testPlayer] = 3;
    gameState->discardCount[testPlayer] = 3;
    gameState->deckCount[testPlayer] = 3;
    gameState->hand[testPlayer][0] = gold;
    gameState->hand[testPlayer][1] = gold;
	gameState->hand[testPlayer][2] = testCard;
	gameState->deck[testPlayer][0] = gold;
    gameState->deck[testPlayer][1] = gold;
	gameState->deck[testPlayer][2] = gold;
	gameState->discard[testPlayer][0] = gold;
    gameState->discard[testPlayer][1] = gold;
	gameState->discard[testPlayer][2] = gold;

	int expectedCardCount = 1;
	if (expectedCardCount == fullDeckCount(testPlayer, testCard, gameState)) {
		printf("fullDeckCount(): PASS when player has one matching card \n");
	}
	else {
		printf("fullDeckCount(): FAIL when player has one matching card \n");
	}
}

void testNoCardsMatch() {
	//setup
	struct gameState* gameState = newGame();
	int testPlayer = 0;
	int testCard = estate;
	int numPlayers = 2;
	int kingdomCards[10] = {adventurer, council_room, feast, gardens, mine, remodel, smithy, village, baron, great_hall};
	int randomSeed = 10;

	if (initializeGame(numPlayers, kingdomCards, randomSeed, gameState) != 0){
		printf("Error initalizing game. \n");
		return;
	}

	//Fill hand, deck, and discard with non-test cards
	//Make sure that the counts are updated
	gameState->handCount[testPlayer] = 3;
    gameState->discardCount[testPlayer] = 3;
    gameState->deckCount[testPlayer] = 3;
    gameState->hand[testPlayer][0] = gold;
    gameState->hand[testPlayer][1] = gold;
	gameState->hand[testPlayer][2] = gold;
	gameState->deck[testPlayer][0] = gold;
    gameState->deck[testPlayer][1] = gold;
	gameState->deck[testPlayer][2] = gold;
	gameState->discard[testPlayer][0] = gold;
    gameState->discard[testPlayer][1] = gold;
	gameState->discard[testPlayer][2] = gold;

	int expectedCardCount = 0;
	if (expectedCardCount == fullDeckCount(testPlayer, testCard, gameState)) {
		printf("fullDeckCount(): PASS when player has no matching cards \n");
	}
	else {
		printf("fullDeckCount(): FAIL when player has no matching cards \n");
	}
}


void testNoCards() {
	//setup
	struct gameState* gameState = newGame();
	int testPlayer = 0;
	int testCard = estate;
	int numPlayers = 2;
	int kingdomCards[10] = {adventurer, council_room, feast, gardens, mine, remodel, smithy, village, baron, great_hall};
	int randomSeed = 10;
	
	if (initializeGame(numPlayers, kingdomCards, randomSeed, gameState) != 0){
		printf("Error initalizing game. \n");
		return;
	}

	//set player 1's hand, deck, and discard count to 0;
	gameState->handCount[testPlayer] = 0;
    gameState->discardCount[testPlayer] = 0;
    gameState->deckCount[testPlayer] = 0;

    int expectedCardCount = 0;
	if (expectedCardCount == fullDeckCount(testPlayer, testCard, gameState)) {
		printf("fullDeckCount(): PASS when player has no cards \n");
	}
	else {
		printf("fullDeckCount(): FAIL when player has no cards \n");
	}
}

